{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "from sympy.abc import *\n",
    "from sympy import sin, cos, pi\n",
    "import numpy as np\n",
    "from IPython.display import display, Math\n",
    "from handcalcs import *\n",
    "from sympy.physics.hydrogen import*\n",
    "f,g= symbols('f g', cls=Function)\n",
    "w_0,w_1,w_2,v_0,v_1,J_0,J_1,J_A,J_B,m_1,m_2,J_2= symbols('w_0 w_1 w_2 v_0 v_1,J_0,J_1,J_A,J_B,m_1,m_2,J_2')\n",
    "beta=symbols('beta')\n",
    "def out(x,x_1=0,x_2=0,x_3=0,x_4=0,x_5=0,x_6=0,x_7=0,x_8=0,x_9=0,x_10=0,x_11=0):\n",
    "   if x==0:\n",
    "      return\n",
    "   if x_1==0:\n",
    "       display(Math(latex(x)))\n",
    "   else:\n",
    "       if type(x_1)==str:\n",
    "          display(Math(x_1+latex(x)))\n",
    "       else:\n",
    "           display(Math(latex(x)))\n",
    "   out(x_2,x_3)\n",
    "   out(x_4,x_5)\n",
    "   out(x_6,x_7)\n",
    "   out(x_8,x_9)\n",
    "   out(x_10,x_11)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一、对弧长的曲线积分\n",
    "主要是如何把$ds$化成可以积分的形式，在式子中进行求导获得$ds$和其他$d$的关系\n",
    "$$ds=\\sqrt{dx^2+dy^2+dz^2}$$\n",
    "> + 稍微注意一下`对称性`和`轮换性`的使用\n",
    "\n",
    "> + 椭圆`弧长`没有精确解\n",
    "\n",
    "> + 闭合:$\\oint_L  正常：\\int_L$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、第二类曲线积分\n",
    "$$\\cos a \\times ds=\\frac{dx}{\\sqrt[]{dx^2+dy^2+dz^2} }$$\n",
    "> + 注意第二类曲线积分有`方向`的区别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{1}{2}$"
      ],
      "text/plain": [
       "1/2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f=sin(x)*cos(x)\n",
    "integrate(f,(x,0,pi/2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、格林公式\n",
    "`正向:`区域在左边\n",
    "\n",
    "`格林公式:`曲线积分与二重积分的关系(`如果具有一阶连续偏导数，不连续的，找圆`)\n",
    "$$\\int_LP dx+\\int_LQ dy=\\int\\int _D(Q'_x-P'_y)$$\n",
    "> + 注意必须是封闭曲线！不是封闭的加线\n",
    "\n",
    "`利用格林公式求面积：`\n",
    "取$P=y,Q=x$,就有$S=\\frac{1}{2}\\oint_L(xdy-ydx)$\n",
    "\n",
    "> + 注意椭圆的$a,b$在分母的位置\n",
    "`与路径无关：`找闭合曲线，用格林公式\n",
    "\n",
    "`全微分：`\n",
    "> + 必要性：混合偏导数相等\n",
    "\n",
    "`注意在原点偏导不连续的情况`\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def out1(P,Q,x1=0,x2=0,y1=0,y2=0):\n",
    "  a=Derivative(Q,x)\n",
    "  b=Derivative(P,y)\n",
    "  a1=diff(Q,x)\n",
    "  b1=diff(P,y)\n",
    "  out(factor(a1),latex(a)+'=',factor(b1),latex(b)+'=')\n",
    "  a2=Integral(P,x) \n",
    "  b2=Integral(P,y)\n",
    "  a3=integrate(P,(x,x1,x2))\n",
    "  b3=integrate(Q,(y,y1,y2))\n",
    "  out(factor(a3),latex(a2)+'=',factor(b3),latex(b2)+'=')\n",
    "#out1(P,Q,3,1,Rational(2/3),2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 0$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# def q5():\n",
    "#     m=cos(t)\n",
    "#     n=sin(t)\n",
    "#     x=m\n",
    "#     y=n\n",
    "#     z=x-y\n",
    "#     return integrate((z-y)*diff(x,t)+(x-z)*diff(y,t)+(x-y)*diff(z,t),(t,2*pi,0))\n",
    "factor(diff(y/(x**2+2*y**2),y)-diff(-x/(x**2+2*y**2),x))"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cfd91be41b1f8570f9fdd3f69120b4c4e0aca43f7ba853244af0f553a22439ed"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
